/**
 * @author rxliuli
 */
const {
    arrayToMap,
    CombinedPredicate: {
        not,
        and,
    },
    compose,
    toString,
    compare,
    stringValidator: {
        isBlank,
    },
} = rx
const validate = (() => {
    const {
        limitLen,
    } = RxElemValidator
    return RxFormValidator.generate([
        limitLen('unitName', '[客户名称] 长度最大为 50 位', 50),
        limitLen('idNumber', '[证件号码] 长度最大为 50 位', 50),
        limitLen('recordNumber', '[备案号或许可证号] 长度最大为 64 位', 64),

        limitLen('startIp', '[起始IP地址] 长度最大为 64 位', 64),
        limitLen('endIp', '[终止IP地址] 长度最大为 64 位', 64),
        limitLen('useCompany', '[使用单位] 长度最大为 64 位', 64),
    ])
})()
const app = new BasicTableVue({
    data() {
        return {
            api: baseCustomerApi,
            columns: [
                new TableColumn({width: 30, type: 'selection'}),
                new TableColumn({prop: 'id', title: 'ID'}),
                new TableColumn({prop: 'unitName', title: '单位名称'}),
                new TableColumn({
                    prop: 'userType',
                    title: '用户类型',
                    formatter: fieldFormatter.facade(fieldFormatter.baseCustomer.userTypeMap),
                }),
                new TableColumn({
                    prop: 'unitNature',
                    title: '单位属性',
                    formatter: fieldFormatter.facade(fieldFormatter.baseCustomer.unitNatureMap),
                }),
                new TableColumn({
                    prop: 'idType',
                    title: '证件类型',
                    formatter: fieldFormatter.facade(fieldFormatter.baseCustomer.idTypeMap),
                }),
                new TableColumn({prop: 'idNumber', title: '证件号码'}),
                new TableColumn({prop: 'officerName', title: '安全责任人'}),
                new TableColumn({prop: 'houseName', title: '所在机房'}),
                new TableColumn({prop: 'domain', title: '服务域名', customComponent: true}),
                new TableColumn({
                    prop: 'reportStatus',
                    title: '报备阶段',
                    formatter: fieldFormatter.facade(fieldFormatter.baseData.reportStatusMap),
                }),
                new TableColumn({prop: 'registerTime', title: '注册时间', formatter: TableColumn.dateFormat}),
                new TableColumn({prop: 'operating', title: '操作', customComponent: true,width:150}),
            ],
            excludeFieldSet: new Set(['registerTimeRange', 'updateTimeRange']),
            houseList: [],
            validate,
        }
    },
    methods: {
        domainToArray({row}) {
            return row.domain && row.domain.split(',')
        },
        createForm() {
            return new BaseCustomer({
                houseId: '',
                registerTimeRange: [],
                updateTimeRange: [],
            })
        },
        viewInfo(row) {
            forward('/basic-data/see/admin_user_info_see', row)
        },
        async insertReport(id) {
            if (await ajaxOption({
                res: this.api.insertReport(id),
                danger: '新增上报失败',
                success: '新增上报成功',
            })) {
                await this.searchPage()
            }
        },
        async updateReport(id) {
            if (await ajaxOption({
                res: this.api.updateReport(id),
                danger: '修改上报失败',
                success: '修改上报成功',
            })) {
                await this.searchPage()
            }
        },
        async downloadTemplate() {
            await baseCustomerApi.downloadTemplate('客户信息管理导入模板.xlsx');
        },
        async init() {
            this.houseList = await baseHouseInfoApi.selectList();
        },
    },
})
